package com.gl.saasservice.house.controller;

import com.gl.framework.web.response.Result;
import com.gl.saasservice.house.entity.HouseType;
import com.gl.saasservice.house.service.HouseService;
import com.gl.saasservice.house.vo.CommunityVO;
import com.gl.saasservice.house.vo.HouseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 公租房、物业房产
 */

@Controller
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private HouseService houseService;

    /**
     * 查询列表
     */
    @GetMapping("/pageslist")
    @ResponseBody
    public Result pageslist(@RequestHeader String token,
                            @RequestParam(defaultValue = "0") Integer pageNumber,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            HouseVO vo) {
        return houseService.pageslist(token, pageNumber, pageSize, vo);
    }

    /**
     * 查询公租房、物业房产总体情况
     */
    @GetMapping("/totallist")
    @ResponseBody
    public Result totallist(@RequestHeader String token){

        return houseService.totallist(token);
    }

    /**
     * 查询小区
     *
     * @return
     */
    @GetMapping("/findCommunity")
    @ResponseBody
    public Result findCommunity(@RequestHeader String token) {
        return houseService.findCommunity(token);
    }

    /**
     * 查询楼栋
     *
     * @param communityId
     * @return
     */
    @GetMapping("/findBuild")
    @ResponseBody
    public Result findBuild(@RequestParam(value = "communityId") String communityId) {
        return houseService.findBuild(communityId);
    }

    /**
     * 查询单元
     *
     * @param buildId,communityId
     * @return
     */
    @GetMapping("/findUnit")
    @ResponseBody
    public Result findUnit(@RequestParam(value = "communityId") String communityId,
                                                          @RequestParam(value = "buildId") Long buildId) {
        return houseService.findUnit(communityId, buildId);
    }

    /**
     * 查询房号
     */
    @GetMapping("/findRoomNumber")
    @ResponseBody
    public Result findRoomNumber(@RequestParam(value = "communityId") String communityId,
                                                                   @RequestParam(value = "buildId") Long buildId,
                                                                   @RequestParam(value = "unitId") Long unitId){

        return houseService.findRoomNumber(communityId, buildId, unitId);
    }

    /**
     * 根据社区查询小区
     */
    @GetMapping("/findCommunityByArea")
    @ResponseBody
    public Result findCommunityByArea(@RequestHeader String token,Long area){

        return houseService.findCommunityByArea(token,area);
    }

    /**
     * 根据市id查询小区
     */
    @GetMapping("/findCommunityByCityId")
    @ResponseBody
    public Result findCommunityByCityId(@RequestHeader String token,Long cityId){

        return houseService.findCommunityByCityId(token,cityId);
    }

    /**
     * 当前省下的所有物业
     */
    @GetMapping("/findByProvinceId")
    @ResponseBody
    public Result findByProvinceId(@RequestHeader String token,Long  provinceId){

        return houseService.findByProvinceId(token, provinceId);
    }

    /**
     *  编辑小区物业
     */
    @PutMapping("/communityProperty")
    @ResponseBody
    public Result communityProperty(@RequestHeader String token, @RequestBody CommunityVO vo){

        return houseService.communityProperty(token,vo);
    }

    /**
     * 公租房--修改产权所有人
     * @param token
     * @param houseId
     * @param orgId
     * @return
     */
    @PutMapping("/updateBindOwner")
    @ResponseBody
    public Result updateBindOwner(@RequestHeader String token,
                                              @RequestParam(value = "houseId") String houseId,
                                              @RequestParam(value = "orgId") Long orgId) {
        return houseService.updateBindOwner(token, houseId, orgId);
    }

    /**
     * 物业房产--物业房产只是填写了产权所有人姓名与电话，所以提供修改姓名与电话方式
     *  @param ownerName 产权所有人姓名
     *  @param ownerMobile 产权所有人电话
     *  @param houseId  房产id
     */
    @PutMapping("/updatePropertyOwner")
    @ResponseBody
    public Result updatePropertyOwner(@RequestHeader String token,String ownerName,String ownerMobile,String houseId){

        return houseService.updatePropertyOwner( token, ownerName, ownerMobile, houseId);
    }

    /**
     * 公租房-产权人列表
     *
     * @param token
     * @param provinceId  省id
     * @return
     */
    @GetMapping("/ownerList")
    @ResponseBody
    public Result ownerList(@RequestHeader String token,
                                             @RequestParam(value = "provinceId", required = false) String provinceId) {
        return houseService.ownerList(token, provinceId);
    }

    /**
     *   删除
     *   公租房：已配租的不能删除，出租状态为：已过期可以删除
     *   物业房产：有账单的不能删除。
     */
    @DeleteMapping()
    @ResponseBody
    public Result delete(@RequestHeader String token,@RequestParam(value = "id", required = false) String id,@RequestParam(value = "type", required = false) Integer type){

        return houseService.delete(token,id,type);
    }

    /**
     * 新增、修改房屋类型
     * @param token
     * @param houseType 房屋类型
     * @return
     */
    @PostMapping ("/houseType")
    @ResponseBody
    public Result houseType(@RequestHeader String token,
                            @RequestBody HouseType houseType) {
        return houseService.houseType(token, houseType);
    }
    /**
     * 查询房屋类型
     * @param token
     * @return
     */
    @GetMapping("/findHouseType")
    @ResponseBody
    public Result findHouseType(@RequestHeader String token) {
        return houseService.findHouseType(token);
    }
    /**
     *   删除房屋类型
     *
     */
    @DeleteMapping("deleteHouseType")
    @ResponseBody
    public Result deleteHouseType(@RequestHeader String token,@RequestParam(value = "id", required = false) Long id){

        return houseService.deleteHouseType(token,id);
    }
    /**
     *   删除小区
     *
     */
    @DeleteMapping("deleteCommunity")
    @ResponseBody
    public Result deleteCommunity(@RequestHeader String token,@RequestParam(value = "id", required = false) String id){

        return houseService.deleteCommunity(token,id);
    }

}
